<?php
/**
 * @Notes: 公众号：ZERO开发
 * @Interface getCondition
 * @Return mixed
 * @Author: bqs
 * @Time: 2021/4/19 15:28
 */

namespace app\common\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\console\input\Option;
use think\Db;
use think\facade\Hook;
use think\facade\Log;
use QL\QueryList;

class QueryListSpiderSingle extends Command
{

    protected function configure()
    {
        $this->setName('querylist:single')
            ->setDescription('采集');
    }

    protected function execute(Input $input, Output $output)
    {
        ini_set('memory_limit', '512M');

        $output->writeln("=========date:" . date('Y-m-d H:i:s') . "===============");

        // 北桥苏奥特曼
        //$slImgsUrl = "https://zhuanlan.zhihu.com/p/377571373";
        $slImgsUrl = "https://zhuanlan.zhihu.com/p/344680014";

        // 原生query_list
        $list = QueryList::get($slImgsUrl)->find('.RichText')->find('noscript')->find('img')->attrs('src');

        $path = 'E:\2setsoft\1dev\phpstudy_pro\WWW\4test\tensorflowJs\js-ml-code\t7\动漫分类\train\奥特曼\\';
        foreach($list as $key => $value) {
            $index = $key + 1 + 42;

            $filename = $index < 10 ? str_pad($index, 2, "0", STR_PAD_LEFT) : $index;
            $filend = pathinfo($value, PATHINFO_EXTENSION);
            $file = file_get_contents($value);
            file_put_contents($path . $filename . "." . $filend, $file);

            $output->writeln($index . "--" . $value . "已保存--");
        }

        $output->writeln("============date:" .date("Y-m-d H:i:s") . "采集完成==============");
    }

}